package cn.yl.caner.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;

import cn.yl.caner.domain.ChangeData;
import cn.yl.caner.utils.DataSourceUtils;
import cn.yl.caner.utils.MyDataSourceUtils;

public class ChangeDao {
		//这个是改变账号信息的DAO层；
	public int changeAccount(ChangeData changedata) throws SQLException {
		int i = 0;
		DataSource ds = DataSourceUtils.getDataSource() ;
		Connection con = MyDataSourceUtils.getConnection();
		QueryRunner qr = new QueryRunner(ds);
		if(changedata.getChange_password() == "") {
			
		}else {
			String sql_username = "update account set password = ? where username = ?";
			qr.update(con,sql_username,changedata.getChange_password(),changedata.getChange_hidden());
			i=i+1;
		}
		if(changedata.getChange_email() == "") {
			
		}else {
			String sql_email = "update account set email = ? where username = ?";
			qr.update(con,sql_email,changedata.getChange_email(),changedata.getChange_hidden());
			i=i+1;
		}
		if(changedata.getChange_phone() == "") {
			
		}else {
			String sql_phone = "update account set phone = ? where username = ?";
			qr.update(con,sql_phone,changedata.getChange_phone(),changedata.getChange_hidden());
			i=i+1;
		}
		return i;
	}
}
